package org.lisen.controlleradvice.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author laughing
 * @date 2020/9/26
 * @site https://www.lisen.org
 */
@RestController
public class TestGlobalExceptionController {

    /**
     * 测试越界异常
     *
     * @return String
     */
    @RequestMapping("/testIndexOutOfBoundsException")
    public String testIndexOutOfBoundsException() {
        String[] names = {"张三"};
        return names[2];
    }

    /**
     * 测试空引用异常
     *
     * @return String
     */
    @RequestMapping("/testNullPointerException")
    public String testNullPointerException() {
        String firstName = null;
        String lastName = "laughing";
        return firstName.toLowerCase() + lastName;
    }

    /**
     * 这个异常不会被处理
     *
     * @return String
     */
    @RequestMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这个异常不会被处理");
    }

}
